﻿using System;
using System.Text.RegularExpressions;
using System.Web.Mvc;
using System.Web.Routing;
using Ninject;
using SocialNetwork.Domain.Repositories;
using SocialNetwork.Domain.Repositories.Interfaces;

namespace SocialNetwork.Infrastructure
{
    public class NinjectControllerFactory : DefaultControllerFactory
    {
        private readonly IKernel ninjectKernel;

        public NinjectControllerFactory()
        {
            ninjectKernel = new StandardKernel();
            AddBindings();
        }

        protected override IController GetControllerInstance(RequestContext requestContext,
                                                             Type controllerType)
        {
            return controllerType == null
                       ? null
                       : (IController) ninjectKernel.Get(controllerType);
        }

        private void AddBindings()
        {
            ninjectKernel.Bind<IScheduleRepository>().To<ScheduleRepository>();
        }
    }
}